```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Java并发编程工具包(JUC)详解</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background-color: #f8fafc;
            color: #1e293b;
            line-height: 1.6;
        }
        .hero {
            background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
            color: white;
        }
        .code-block {
            background-color: #1e293b;
            color: #e2e8f0;
            border-radius: 0.5rem;
            overflow-x: auto;
        }
        .card {
            transition: transform 0.3s ease, box-shadow 0.3s ease;
            border-radius: 0.75rem;
        }
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .section-divider {
            border: none;
            height: 1px;
            background-image: linear-gradient(to right, rgba(0, 0, 0, 0), rgba(79, 70, 229, 0.5), rgba(0, 0, 0, 0));
        }
        .highlight {
            position: relative;
        }
        .highlight::before {
            content: "";
            position: absolute;
            left: 0;
            bottom: 0;
            width: 100%;
            height: 30%;
            background-color: rgba(167, 139, 250, 0.3);
            z-index: -1;
            transform: rotate(-1deg);
        }
    </style>
</head>
<body class="antialiased">
    <!-- Hero Section -->
    <div class="hero min-h-screen flex items-center">
        <div class="container mx-auto px-6 py-20">
            <div class="max-w-3xl mx-auto text-center">
                <h1 class="text-5xl md:text-6xl font-bold mb-6 font-serif">Java并发编程工具包(JUC)</h1>
                <p class="text-xl md:text-2xl mb-8 opacity-90 font-light">解锁高性能多线程应用的强大工具集</p>
                <div class="inline-flex items-center space-x-4">
                    <span class="bg-white text-indigo-600 px-4 py-2 rounded-full text-sm font-medium">高并发</span>
                    <span class="bg-white text-indigo-600 px-4 py-2 rounded-full text-sm font-medium">多线程</span>
                    <span class="bg-white text-indigo-600 px-4 py-2 rounded-full text-sm font-medium">异步编程</span>
                </div>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="container mx-auto px-6 py-12 max-w-6xl">
        <!-- JUC Introduction -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-6 text-indigo-700 flex items-center">
                <i class="fas fa-tools mr-4"></i>
                <span class="highlight">什么是JUC</span>
            </h2>
            <div class="grid grid-cols-1 md:grid-cols-2 gap-8">
                <div>
                    <p class="text-lg text-gray-700 mb-4">
                        JUC是Java并发编程工具包，是java.util.concurrent包的简称。它的目的是为了更好的支持高并发任务，让开发者利用这个包进行多线程开发时，可以有效的减少竞争条件和死锁线程。
                    </p>
                    <div class="bg-indigo-50 p-6 rounded-lg border-l-4 border-indigo-500">
                        <div class="flex items-start">
                            <i class="fas fa-lightbulb text-indigo-500 mt-1 mr-3"></i>
                            <p class="text-indigo-800">
                                JUC提供了一系列高级同步工具和并发容器，如线程池Executor框架、并发集合类、同步器(如CountDownLatch、CyclicBarrier)等，是现代Java并发编程的基础。
                            </p>
                        </div>
                    </div>
                </div>
                <div class="flex items-center justify-center">
                    <div class="mermaid">
                        pie title JUC核心组件
                            "线程池" : 35
                            "并发集合" : 25
                            "同步器" : 20
                            "原子类" : 15
                            "其他" : 5
                    </div>
                </div>
            </div>
        </section>

        <!-- Async Programming -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-6 text-indigo-700 flex items-center">
                <i class="fas fa-bolt mr-4"></i>
                <span class="highlight">异步编程</span>
            </h2>
            <div class="bg-white rounded-xl shadow-lg overflow-hidden mb-8">
                <div class="p-6">
                    <h3 class="text-xl font-semibold mb-4 text-indigo-600">用户下单操作流程</h3>
                    <p class="mb-6 text-gray-700">同步执行耗时3秒，如何通过异步优化？</p>
                    <div class="space-y-4">
                        <div class="flex items-center">
                            <div class="w-8 h-8 rounded-full bg-indigo-100 text-indigo-600 flex items-center justify-center mr-4">
                                1
                            </div>
                            <div class="flex-1">根据地址id查询地址信息 <span class="text-gray-500 ml-2">0.5s</span></div>
                        </div>
                        <div class="flex items-center">
                            <div class="w-8 h-8 rounded-full bg-indigo-100 text-indigo-600 flex items-center justify-center mr-4">
                                2
                            </div>
                            <div class="flex-1">查询用户购物车的数据 <span class="text-gray-500 ml-2">0.5s</span></div>
                        </div>
                        <div class="flex items-center">
                            <div class="w-8 h-8 rounded-full bg-indigo-100 text-indigo-600 flex items-center justify-center mr-4">
                                3
                            </div>
                            <div class="flex-1">查询购物车中的商品信息 <span class="text-gray-500 ml-2">1s</span></div>
                        </div>
                        <div class="flex items-center">
                            <div class="w-8 h-8 rounded-full bg-indigo-100 text-indigo-600 flex items-center justify-center mr-4">
                                4
                            </div>
                            <div class="flex-1">创建订单 <span class="text-gray-500 ml-2">0.5s</span></div>
                        </div>
                        <div class="flex items-center">
                            <div class="w-8 h-8 rounded-full bg-indigo-100 text-indigo-600 flex items-center justify-center mr-4">
                                5
                            </div>
                            <div class="flex-1">创建订单详情 <span class="text-gray-500 ml-2">0.5s</span></div>
                        </div>
                        <div class="flex items-center">
                            <div class="w-8 h-8 rounded-full bg-indigo-100 text-indigo-600 flex items-center justify-center mr-4">
                                6
                            </div>
                            <div class="flex-1">扣减库存</div>
                        </div>
                    </div>
                </div>
                <div class="bg-gray-50 px-6 py-4 border-t border-gray-100">
                    <p class="text-sm text-gray-600 flex items-center">
                        <i class="fas fa-question-circle mr-2"></i>
                        用户创建一个订单总共耗时3s，每个操作都是同步执行的。如果变成异步是否会提高性能？
                    </p>
                </div>
            </div>
            
            <div class="mermaid">
                gantt
                    title 同步 vs 异步执行时间对比
                    dateFormat  X
                    axisFormat %s
                    section 同步执行
                    任务1 : 0, 0.5s
                    任务2 : 0.5, 1s
                    任务3 : 1, 2s
                    任务4 : 2, 2.5s
                    任务5 : 2.5, 3s
                    section 异步执行
                    任务1 : 0, 0.5s
                    任务2 : 0, 0.5s
                    任务3 : 0, 1s
                    任务4 : 0, 0.5s
                    任务5 : 0, 0.5s
            </div>
        </section>

        <!-- CompletableFuture -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-6 text-indigo-700 flex items-center">
                <i class="fas fa-code-branch mr-4"></i>
                <span class="highlight">CompletableFuture</span>
            </h2>
            <p class="text-lg text-gray-700 mb-8">
                Java8新增了CompletableFuture提供对异步计算的支持，可以通过回调的方式处理计算结果。它提供了丰富的API来组合多个异步操作，实现复杂的异步编程模式。
            </p>
            
            <div class="grid grid-cols-1 md:grid-cols-2 gap-8 mb-10">
                <!-- RunAsync & SupplyAsync -->
                <div class="card bg-white p-6 shadow-md">
                    <h3 class="text-xl font-semibold mb-4 text-indigo-600 flex items-center">
                        <i class="fas fa-play mr-2"></i>runAsync 和 supplyAsync方法
                    </h3>
                    <div class="code-block p-4 mb-4">
                        <pre><code class="text-sm">public static CompletableFuture&lt;Void&gt; runAsync(Runnable runnable)
public static CompletableFuture&lt;Void&gt; runAsync(Runnable runnable, Executor executor)
public static &lt;U&gt; CompletableFuture&lt;U&gt; supplyAsync(Supplier&lt;U&gt; supplier)
public static &lt;U&gt; CompletableFuture&lt;U&gt; supplyAsync(Supplier&lt;U&gt; supplier, Executor executor)</code></pre>
                    </div>
                    <p class="text-gray-700">
                        CompletableFuture 提供了四个静态方法来创建一个异步操作。没有指定Executor的方法会使用ForkJoinPool.commonPool() 作为它的线程池执行异步代码。
                    </p>
                    <ul class="mt-4 space-y-2 text-gray-700">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-indigo-500 mr-2 mt-1"></i>
                            <span>runAsync方法不支持返回值</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-indigo-500 mr-2 mt-1"></i>
                            <span>supplyAsync可以支持返回值</span>
                        </li>
                    </ul>
                </div>
                
                <!-- Callback Methods -->
                <div class="card bg-white p-6 shadow-md">
                    <h3 class="text-xl font-semibold mb-4 text-indigo-600 flex items-center">
                        <i class="fas fa-redo mr-2"></i>计算结果完成时的回调方法
                    </h3>
                    <div class="code-block p-4 mb-4">
                        <pre><code class="text-sm">public CompletableFuture&lt;T&gt; whenComplete(BiConsumer&lt;? super T,? super Throwable&gt; action)
public CompletableFuture&lt;T&gt; whenCompleteAsync(BiConsumer&lt;? super T,? super Throwable&gt; action)
public CompletableFuture&lt;T&gt; whenCompleteAsync(BiConsumer&lt;? super T,? super Throwable&gt; action, Executor executor)
public CompletableFuture&lt;T&gt; exceptionally(Function&lt;Throwable,? extends T&gt; fn)</code></pre>
                    </div>
                    <p class="text-gray-700">
                        当CompletableFuture的计算结果完成，或者抛出异常的时候，可以执行特定的Action。
                    </p>
                    <div class="mt-4 bg-yellow-50 p-4 rounded-lg">
                        <h4 class="font-medium text-yellow-800 mb-2 flex items-center">
                            <i class="fas fa-exclamation-circle mr-2"></i>注意区别
                        </h4>
                        <ul class="text-yellow-700 text-sm space-y-1">
                            <li>whenComplete: 执行当前任务的线程继续执行</li>
                            <li>whenCompleteAsync: 把任务提交给线程池执行</li>
                            <li>exceptionally: 任务异常时调用，可以改变返回值(降级)</li>
                        </ul>
                    </div>
                </div>
            </div>
            
            <!-- Task Serialization -->
            <div class="card bg-white p-6 shadow-md mb-10">
                <h3 class="text-xl font-semibold mb-4 text-indigo-600 flex items-center">
                    <i class="fas fa-project-diagram mr-2"></i>任务串行化
                </h3>
                <p class="text-gray-700 mb-4">
                    前一个任务执行完才能执行后一个任务。CompletableFuture提供了多种方法来实现任务之间的串行执行。
                </p>
                <div class="code-block p-4 mb-4">
                    <pre><code class="text-sm">// 接收前一个任务的执行结果，并消费处理，该任务没有返回结果 ,可以接收到上一个任务的异常
public CompletionStage&lt;T&gt;  whenComplete(BiConsumer action)
// 不依赖前面任务的执行结果，只要前面任务执行完了，该任务就马上执行
public CompletableFuture&lt;Void&gt; thenRun(Runnable action)
// 接收前一个任务的执行结果，并消费处理，该任务没有返回结果    
public CompletableFuture&lt;Void&gt; thenAccept(Consumer&lt;? super T&gt; action)
// 接收前一个任务的执行结果，并消费，该任务有返回结果  
public &lt;U&gt; CompletableFuture&lt;U&gt; thenApply(Function&lt;? super T,? extends U&gt; fn)
// 接收前一个任务的执行结果，并消费，该任务有返回结果，可以接收到前面任务异常      
public &lt;U&gt; CompletableFuture&lt;U&gt; handle(BiFunction&lt;? super T, Throwable, ? extends U&gt; fn)</code></pre>
                </div>
                <div class="mermaid">
                    flowchart LR
                        A[任务1] -->|thenRun| B[任务2]
                        A -->|thenApply| C[任务3]
                        C -->|thenAccept| D[任务4]
                        D -->|handle| E[任务5]
                </div>
            </div>
            
            <!-- Task Combination -->
            <div class="card bg-white p-6 shadow-md">
                <h3 class="text-xl font-semibold mb-4 text-indigo-600 flex items-center">
                    <i class="fas fa-object-group mr-2"></i>两个任务组合 - 都要完成
                </h3>
                <p class="text-gray-700 mb-4">
                    两个任务都要完成以后，再去触发第三个任务。CompletableFuture提供了多种组合方式。
                </p>
                <div class="code-block p-4 mb-4">
                    <pre><code class="text-sm">// 组合两个任务，不需要获取前两个任务的结果
public CompletableFuture&lt;Void&gt; runAfterBoth(CompletionStage&lt;?&gt; other,Runnable action)
// 组合两个任务，需要前两个任务的返回结果，执行该任务后没有返回结果  
public &lt;U&gt; CompletableFuture&lt;Void&gt; thenAcceptBoth(CompletionStage&lt;? extends U&gt; other, BiConsumer&lt;? super T, ? super U&gt; action)
// 组合两个任务，需要前两个任务的返回结果，执行该任务后有返回结果  
public &lt;U,V&gt; CompletableFuture&lt;V&gt; thenCombine(CompletionStage&lt;? extends U&gt; other,BiFunction&lt;? super T,? super U,? extends V&gt; fn)</code></pre>
                </div>
                <div class="mermaid">
                    flowchart LR
                        A[任务1] --> C[组合任务]
                        B[任务2] --> C
                </div>
            </div>
        </section>

        <!-- Java定时调度机制 -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-6 text-indigo-700 flex items-center">
                <i class="fas fa-clock mr-4"></i>
                <span class="highlight">Java定时调度机制</span>
            </h2>
            <p class="text-lg text-gray-700 mb-6">
                定时任务作为一种系统调度工具，在一些需要有定时作业的系统中应用广泛，如每逢某个时间点统计数据、在将来某个时刻执行某些动作。
            </p>
            
            <!-- ScheduledExecutorService -->
            <div class="card bg-white p-6 shadow-md mb-10">
                <h3 class="text-xl font-semibold mb-4 text-indigo-600 flex items-center">
                    <i class="fas fa-calendar-alt mr-2"></i>ScheduledExecutorService
                </h3>
                <p class="text-gray-700 mb-4">
                    ScheduledExecutorService是JDK提供的一个定时调度类，可以将定时任务与线程池功能结合使用。
                </p>
                
                <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-6">
                    <div>
                        <h4 class="font-medium text-gray-800 mb-2">常用API</h4>
                        <div class="code-block p-4">
                            <pre><code class="text-sm">// 带延迟时间的调度，只执行一次
public ScheduledFuture&lt;?&gt; schedule(Runnable command, long delay, TimeUnit unit);
// 带延迟时间的调度，循环执行，固定频率
public ScheduledFuture&lt;?&gt; scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit);
// 带延迟时间的调度，循环执行，固定延迟
public ScheduledFuture&lt;?&gt; scheduleWithFixedDelay(Runnable command, long initialDelay, long delay, TimeUnit unit);</code></pre>
                        </div>
                    </div>
                    <div>
                        <h4 class="font-medium text-gray-800 mb-2">示例代码</h4>
                        <div class="code-block p-4">
                            <pre><code class="text-sm">ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(10);

// 延时2s后执行，只调用一次
scheduler.schedule(() -> {
    System.out.println("执行任务: " + new Date());
}, 2, TimeUnit.SECONDS);

// 循环执行，固定频率
scheduler.scheduleAtFixedRate(() -> {
    System.out.println("固定频率任务: " + new Date());
}, 0, 5, TimeUnit.SECONDS);</code></pre>
                        </div>
                    </div>
                </div>
                
                <div class="bg-blue-50 p-4 rounded-lg border-l-4 border-blue-500">
                    <h4 class="font-medium text-blue-800 mb-2 flex items-center">
                        <i class="fas fa-info-circle mr-2"></i>固定频率 vs 固定延迟
                    </h4>
                    <ul class="text-blue-700 space-y-1">
                        <li><strong>scheduleAtFixedRate</strong>: 任务执行时间超过了周期时间，直接执行下一个任务</li>
                        <li><strong>scheduleWithFixedDelay</strong>: 任务执行时间超过了周期时间，还要等待周期时间后才执行下一个任务</li>
                    </ul>
                </div>
            </div>
            
            <!-- @Scheduled Annotation -->
            <div class="card bg-white p-6 shadow-md">
                <h3 class="text-xl font-semibold mb-4 text-indigo-600 flex items-center">
                    <i class="fas fa-annotation mr-2"></i>@Scheduled注解
                </h3>
                <p class="text-gray-700 mb-4">
                    Spring 3.0 版本之后自带定时任务，提供了@EnableScheduling注解和@Scheduled注解来实现定时任务功能。
                </p>
                
                <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-6">
                    <div>
                        <h4 class="font-medium text-gray-800 mb-2">基本使用</h4>
                        <div class="code-block p-4">
                            <pre><code class="text-sm">@Component
public class ScheduleTask {
    @Scheduled(cron = "0/2 * * * * ?") // 每2秒执行一次
    public void task1() {
        System.out.println("执行任务: " + new Date());
    }
}

@SpringBootApplication
@EnableScheduling // 开启定时任务
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}</code></pre>
                        </div>
                    </div>
                    <div>
                        <h4 class="font-medium text-gray-800 mb-2">解决单线程问题</h4>
                        <div class="code-block p-4">
                            <pre><code class="text-sm">// 1. 使用@Async注解
@Component
@Async
public class ScheduleTask {
    @Scheduled(cron = "0/2 * * * * ?")
    public void task1() { ... }
}

// 2. 使用自定义线程池
ExecutorService executor = Executors.newFixedThreadPool(10);
@Scheduled(cron = "0/2 * * * * ?")
public void task1() {
    executor.submit(() -> { ... });
}</code></pre>
                        </div>
                    </div>
                </div>
                
                <div class="bg-purple-50 p-4 rounded-lg">
                    <h4 class="font-medium text-purple-800 mb-2 flex items-center">
                        <i class="fas fa-calendar-day mr-2"></i>Cron表达式
                    </h4>
                    <p class="text-purple-700 mb-2">
                        Cron表达式是一个字符串，由6或7个域组成，每个域代表一个时间单位。
                    </p>
                    <div class="overflow-x-auto">
                        <table class="min-w-full bg-white">
                            <thead>
                                <tr class="bg-purple-100">
                                    <th class="py-2 px-4 text-left">域</th>
                                    <th class="py-2 px-4 text-left">允许值</th>
                                    <th class="py-2 px-4 text-left">特殊字符</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr>
                                    <td class="py-2 px-4 border-b">秒</td>
                                    <td class="py-2 px-4 border-b">0-59</td>
                                    <td class="py-2 px-4 border-b">, - * /</td>
                                </tr>
                                <tr>
                                    <td class="py-2 px-4 border-b">分</td>
                                    <td class="py-2 px-4 border-b">0-59</td>
                                    <td class="py-2 px-4 border-b">, - * /</td>
                                </tr>
                                <tr>
                                    <td class="py-2 px-4 border-b">小时</td>
                                    <td class="py-2 px-4 border-b">0-23</td>
                                    <td class="py-2 px-4 border-b">, - * /</td>
                                </tr>
                                <tr>
                                    <td class="py-2 px-4 border-b">日</td>
                                    <td class="py-2 px-4 border-b">1-31</td>
                                    <td class="py-2 px-4 border-b">, - * ? / L W</td>
                                </tr>
                                <tr>
                                    <td class="py-2 px-4 border-b">月</td>
                                    <td class="py-2 px-4 border-b">1-12</td>
                                    <td class="py-2 px-4 border-b">, - * /</td>
                                </tr>
                                <tr>
                                    <td class="py-2 px-4 border-b">周</td>
                                    <td class="py-2 px-4 border-b">1-7</td>
                                    <td class="py-2 px-4 border-b">, - * ? / L #</td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </section>

        <!-- 请求合并 -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-6 text-indigo-700 flex items-center">
                <i class="fas fa-object-ungroup mr-4"></i>
                <span class="highlight">请求合并</span>
            </h2>
            
            <div class="card bg-white p-6 shadow-md mb-8">
                <h3 class="text-xl font-semibold mb-4 text-indigo-600">场景</h3>
                <p class="text-gray-700 mb-4">
                    高并发场景中，调用批量接口相比调用非批量接口有更大的性能优势。请求合并可以将单位时间内的多个单个请求合并为一个批量请求，显著提高系统性能。
                </p>
                <div class="mermaid mb-6">
                    flowchart LR
                        A[用户1] --> C[请求合并器]
                        B[用户2] --> C
                        D[用户3] --> C
                        C --> E[批量查询数据库/Redis]
                        E --> F[分发结果]
                </div>
                <div class="bg-green-50 p-4 rounded-lg border-l-4 border-green-500">
                    <h4 class="font-medium text-green-800 mb-2 flex items-center">
                        <i class="fas fa-bullseye mr-2"></i>请求合并的目的
                    </h4>
                    <ul class="text-green-700 space-y-1">
                        <li>减少访问数据库/Redis的次数</li>
                        <li>将单位时间内的多个请求合并为一个批量请求</li>
                        <li>将单个查询SQL改为批量查询SQL</li>
                        <li>使用Redis的pipeline实现批量操作</li>
                    </ul>
                </div>
            </div>
            
            <div class="grid grid-cols-1 md:grid-cols-2 gap-8">
                <!-- 单个接口 -->
                <div class="card bg-white p-6 shadow-md">
                    <h3 class="text-xl font-semibold mb-4 text-indigo-600">单个接口</h3>
                    <div class="code-block p-4 mb-4">
                        <pre><code class="text-sm">@GetMapping("/info/{id}")
public User info(@PathVariable Integer id) {
    return userService.info(id);
}</code></pre>
                    </div>
                    <p class="text-gray-700">
                        这个接口如果访问频率很高，会对数据库或Redis造成很大压力。
                    </p>
                </div>
                
                <!-- 批量接口 -->
                <div class="card bg-white p-6 shadow-md">
                    <h3 class="text-xl font-semibold mb-4 text-indigo-600">批量接口实现</h3>
                    <div class="code-block p-4 mb-4">
                        <pre><code class="text-sm">@Scheduled(cron = "0/5 * * * * *") // 每5s执行一次
public void actionTask() {
    executorService.submit(() -> {
        List&lt;BatchRequest&gt; list = new ArrayList&lt;&gt;();
        // 从队列中取出任务
        for (int i = 0; i &lt; blockingQueue.size(); i++) {
            list.add(blockingQueue.poll());
        }
        if (list.size() > 0) {
            // 批量查询并分发结果
            List&lt;BatchResult&gt; results = userMapper.batchQuery(list);
            for (BatchRequest request : list) {
                User user = results.stream()...;
                request.getFuture().complete(user);
            }
        }
    });
}</code></pre>
                    </div>
                </div>
            </div>
        </section>

        <!-- Fork/Join框架 -->
        <section>
            <h2 class="text-3xl font-bold mb-6 text-indigo-700 flex items-center">
                <i class="fas fa-code-merge mr-4"></i>
                <span class="highlight">Fork/Join框架</span>
            </h2>
            
            <div class="card bg-white p-6 shadow-md mb-8">
                <p class="text-lg text-gray-700 mb-6">
                    Fork/Join框架是Java 7提供的一个用于并行执行任务的框架，是一个把大任务分割成若干个小任务，最终汇总每个小任务结果后得到大任务结果的框架。
                </p>
                
                <div class="grid grid-cols-1 md:grid-cols-2 gap-8 mb-8">
                    <div>
                        <h3 class="text-xl font-semibold mb-4 text-indigo-600">未拆分请求</h3>
                        <div class="code-block p-4 mb-4">
                            <pre><code class="text-sm">@GetMapping("/sum")
public Integer sum() {
    long start = System.currentTimeMillis();
    Integer sum = 0;
    for (int i = 0; i < 10000; i++) {
        sum += i;
    }
    long end = System.currentTimeMillis();
    System.out.println("time:" + (end - start));
    return sum;
}</code></pre>
                        </div>
                        <p class="text-gray-700">执行时间: ~10000ms</p>
                    </div>
                    
                    <div>
                        <h3 class="text-xl font-semibold mb-4 text-indigo-600">Fork/Join拆分</h3>
                        <div class="code-block p-4 mb-4">
                            <pre><code class="text-sm">@Override
protected Integer compute() {
    if ((end - start) < 100) {
        // 直接计算小任务
    } else {
        // 拆分任务
        int mid = (end + start) / 2;
        ComputeTask left = new ComputeTask(start, mid, task);
        ComputeTask right = new ComputeTask(mid, end, task);
        left.fork(); // 拆分
        right.fork(); // 拆分
        sum = left.join() + right.join(); // 汇总结果
    }
    return sum;
}</code></pre>
                        </div>
                        <p class="text-gray-700">执行时间: ~500ms (提升20倍)</p>
                    </div>
                </div>
                
                <div class="mermaid">
                    flowchart TB
                        A[大任务] --> B[子任务1]
                        A --> C[子任务2]
                        B --> D[子子任务1]
                        B --> E[子子任务2]
                        C --> F[子子任务3]
                        C --> G[子子任务4]
                        D --> H[结果汇总]
                        E --> H
                        F --> H
                        G --> H
                </div>
            </div>
        </section>
    </div>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>
```